package com.system.demo.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.system.demo.entity.database.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


import java.util.List;

@Mapper
public interface StudentMapper extends BaseMapper<Student> {


    default List<Student> selectByUids(List<String> uids) {
        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(Student::getUid, uids);
        return this.selectList(queryWrapper);
    }

    /**
     * 根据uid列表获取id列表
     * @param uids uid列表
     * @return id列表
     */
    @Select("<script>" +
            "SELECT id FROM student WHERE uid IN " +
            "<foreach item='item' index='index' collection='uids' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<Integer> selectIdsByUids(@Param("uids") List<String> uids);

    // 自定义查询，根据 uid 查找 student_name
    @Select("SELECT student_name FROM student WHERE uid = #{uid}")
    String findNameByUid(@Param("uid") String uid);

}
